#ifndef TICKETITEMMODEL_H
#define TICKETITEMMODEL_H

#include <QtCore/QAbstractListModel>
#include <QtGui/QStyledItemDelegate>
#include <QtCore/QList>
#include "ticketquery.h"

class Ticket;
class ITicketExplorerBackend;

class BaseTicketItemModel : public QAbstractListModel
{
    Q_OBJECT
public:
    enum Roles {
        Id = Qt::UserRole + 0,
        Priority,
        Summary,
        Reporter,
        Assignee,
        Status,
        Type,
        Description,
        Created,
        Other = Qt::UserRole + 50 // Backend-specific roles should start from here
    };

    // Initial ticket list
    explicit BaseTicketItemModel(QList<Ticket *> tickets, QObject *parent = 0);
    ~BaseTicketItemModel();

    int rowCount(const QModelIndex &parent) const;
    int columnCount(const QModelIndex &parent) const;
    QVariant data(const QModelIndex &index, int role) const;
    QVariant headerData(int section, Qt::Orientation orientation, int role) const;

    // Not a newly allocated copy
    Ticket *ticketAtIndex(QModelIndex &index);

    void notifyQueryCompleted(int total, int done);
    void setTicketQuery(TicketQuery ticketQuery);
    TicketQuery query();
signals:
    void queryCompleted(int done, int total);

public slots:
    void addTicket(Ticket *ticket);
    void appendTickets(QList<Ticket *> newTickets);

private:
    QString ticketToolTip(const Ticket *ticket) const;

    QList<Ticket *> m_tickets;
    TicketQuery m_query;
};

#endif // TICKETITEMMODEL_H
